<input type="hidden" class="oldcalling" >
<script type="text/javascript">
    var domain = "http://www.mxdxedu.cn";//服务器有公共配置
    var bigCata = [];
    var cata = [];
    var cata2 = [];
    var smallCate = [];

    $("#btnWishTrade").click(function(){
        $.ajax({
            type:"GET",
            url:domain+"/p/getRecruitmentDictList?type=2&parentIdisNull=1", //访问的链接
            dataType:"jsonp",  //数据格式设置为jsonp
            jsonp:"callback",  //Jquery生成验证参数的名称
            success:function(data){  //成功的回调函数
                bigCata = data;
                var html = "<ul>";
                for(var i=0;i<bigCata.length;i++){
                    html += "<li class='bigcata' data="+bigCata[i].id+" style='cursor: pointer;' ><label>"+bigCata[i].name+"</label></li>";
                }
                html +="</ul>";
                $(".choiceLst").html(html);
                $("._btnAreaClear").attr("data",1);

                //获取选中的值
                var ids = $("#calling").val();
                $(".oldcalling").val(ids);
                if(ids){
                    var cataArr = getString(ids,",");
                    var cataNames = $(".callinghtml").html();
                    var cataNameArr = getString(cataNames,",");
                    var choice = '';
                    for(var i=0;i<cataArr.length;i++){
                        choice += '<li class="'+cataArr[i]+'"><label><input type="checkbox" class="popChkdel" data="'+cataNameArr[i]+'" value="'+cataArr[i]+'" checked="checked">'+cataNameArr[i]+'</label></li>';
                    }
                }
                $("#_selected").append(choice);

                $(".dialogMask,.choice").show();
            },
            error: function (e) {
                console.log(e);
            }
        });






    })
    $(document).on("click", ".bigcata", function(){
        $(".cateul,.smallcateul").remove();
        var id = $(this).attr("data");//根据id去请求子类  假如得到的子类为cata
        $.ajax({
            type:"GET",
            url:domain+"/p/getRecruitmentDictList?type=2&parentId="+id, //访问的链接
            dataType:"jsonp",  //数据格式设置为jsonp
            jsonp:"callback",  //Jquery生成验证参数的名称
            success:function(data){  //成功的回调函数
                cata = data;
                var html = "<ul class='cateul'>";
                var ids = $("#calling").val();
                var cataArr = getString(ids,",");
                for(var i=0;i<cata.length;i++){
                    if(cata[i].isLeaf == 0){
                        html += "<li class='cata' data="+cata[i].id+" style='cursor: pointer;' ><label>"+cata[i].name+"</label></li>";
                    }else{
                        if($.inArray(cata[i].id, cataArr)==-1){
                            var check='';
                        }else{
                            var check='checked="checked"';
                        }
                        html += "<li class='cata' data="+cata[i].id+" style='cursor: pointer;' ><label><input type='checkbox' class='popChk cata_"+cata[i].id+"' name='cata' "+check+" data_name="+cata[i].name+" value="+cata[i].id+" >"+cata[i].name+"</label></li>";
                    }
                }
                html +="</ul>";
                $(".choiceLst").append(html);
            },
            error: function (e) {

            }
        });


        //}
    });
    $(document).on("click", ".cata", function(){
        $(".smallcateul").remove();
        var id = $(this).attr("data");//根据id去请求子类  假如得到的子类为smallCata
        $.ajax({
            type:"GET",
            url:domain+"/p/getRecruitmentDictList?type=2&parentId="+id, //访问的链接
            dataType:"jsonp",  //数据格式设置为jsonp
            jsonp:"callback",  //Jquery生成验证参数的名称
            success:function(data){  //成功的回调函数
                smallCate = data;
                var html = "<ul class='smallcateul'>";
                var ids = $("#calling").val();
                var cataArr = getString(ids,",");
                for(var i=0;i<smallCate.length;i++){
                    if(smallCate[i].isLeaf == 0){
                        html += "<li class='smallcata' data="+smallCate[i].id+" style='cursor: pointer;' ><label>"+smallCate[i].name+"</label></li>";
                    }else{
                        if($.inArray(smallCate[i].id, cataArr)==-1){
                            var check='';
                        }else{
                            var check='checked="checked"';
                        }
                        html += "<li class='smallcata' data="+smallCate[i].id+" style='cursor: pointer;' ><label><input type='checkbox'  class='popChk cata_"+smallCate[i].id+"' name='smallcata' "+check+" data_name="+smallCate[i].name+" value="+smallCate[i].id+">"+smallCate[i].name+"</label></li>";
                    }
                }
                html +="</ul>";
                $(".choiceLst").append(html);
            },
            error: function (e) {

            }
        });
        //}
    });

    $(document).on("click", ".popChk", function(){
        var ids = $("#calling").val();
        //console.log($(this).val());
        var id = $(this).val();
        //console.log($(this).attr("data_name"));
        var cataName = $(this).attr("data_name");
        var cataNames = $(".callinghtml").html();
        if($(this).prop("checked")){
            if(ids){
                var cataArr = getString(ids,",");
                cataArr = addKey(cataArr,id);
                if(!cataArr){
                    return false;
                }
                $("#calling").val(cataArr.join());
                $("#calling").trigger("change");
                var cataHtmlArr = getString(cataNames,",");
                cataHtmlArr = addKey(cataHtmlArr,cataName);
                $(".callinghtml").html(cataHtmlArr.join());
            }else{
                $("#calling").val(id);
                $("#calling").trigger("change");
                $(".callinghtml").html(cataName);
            }
            $("#_selected").append('<li class="'+id+'"><label><input type="checkbox" class="popChkdel" data="'+cataName+'" value="'+id+'" checked="checked">'+cataName+'</label></li>');
        }else{
            var cataArr = getString(ids,",");
            cataArr = delkey(cataArr,id);
            $("."+id).remove();
            $("#calling").val(cataArr.join());
            $("#calling").trigger("change");
            var cataHtmlArr = getString(cataNames,",");
            cataHtmlArr = delkey(cataHtmlArr,cataName);
            if(cataHtmlArr.join()==''){
                $(".callinghtml").html("请选择");
            }else{
                $(".callinghtml").html(cataHtmlArr.join());
            }
        }
    })
    $(document).on("click", ".popChkdel", function(){
        var id = $(this).val();
        var cataName = $(this).attr("data");
        var ids = $("#calling").val();
        var cataArr = getString(ids,",");
        cataArr = delkey(cataArr,id);
        $("."+id).remove();
        $("#calling").val(cataArr.join());
        $("#calling").trigger("change");
        $(".cata_"+id).attr("checked",false);

        var cataNames = $(".callinghtml").html();
        var cataHtmlArr = getString(cataNames,",");
        cataHtmlArr = delkey(cataHtmlArr,cataName);
        if(cataHtmlArr.join()==''){
            $(".callinghtml").html("请选择");
        }else{
            $(".callinghtml").html(cataHtmlArr.join());
        }

    })
</script>